package com.vr.caricature.fenlei;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.vr.caricature.R;
import com.vr.caricature.common.BaseVideoActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by chengxiaozhi on 2016/11/3.
 */

public class VideoFragment extends Fragment implements AdapterView.OnItemClickListener{

    @InjectView(R.id.gv_video)GridView gvVideo;

    private VideoAdapter mVAdapter;

    private int mNum; //页号


    public static VideoFragment newInstance(int num) {
        VideoFragment fragment = new VideoFragment();
        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putInt("num", num);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //这里我只是简单的用num区别标签，其实具体应用中可以使用真实的fragment对象来作为叶片
        mNum = getArguments() != null ? getArguments().getInt("num") : 1;
    }


    /**为Fragment加载布局时调用**/
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg_video,container,false);
        ButterKnife.inject(this,view);
        mVAdapter = new VideoAdapter(getActivity());
        gvVideo.setAdapter(mVAdapter);
        gvVideo.setOnItemClickListener(this);
        return view;
    }




    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        startActivity(new Intent(getActivity(), BaseVideoActivity.class));

    }
}
